function out=get_wrapp_window(img,window_size,point,img_size)
%computes the wrapping window according to a given window_size by adding
%all sub_windows
%
%
% Author: Sebastian Schmelcher         Version: 2012-06-22

out=zeros(window_size);
if(nargin<3)
    img_size=size(img);
    ys=img_size(1);
    xs=img_size(2);
else
    ys=size(img,1);
    xs=size(img,2);
end

yw=window_size(1);
xw=window_size(2);

origin=get_origin(img_size);
yo=origin(1)-floor(yw/2);
xo=origin(2)-floor(xw/2);


ystart=yo-ceil(yo/yw)*yw;
xstart=xo-ceil(xo/xw)*xw;

if(nargin>2)   
    
    %find the left upper window from point
    while(ystart+yw<point(1))
       ystart=ystart+yw;
   end
   while(xstart+xw<point(3))
       xstart=xstart+xw;
   end
   
   ystart=ystart-point(1)+1;
   xstart=xstart-point(3)+1;

end

xnow=xstart;
ynow=ystart;

while(ynow<ys)
    while(xnow<xs)
        %window is added, boundaries are taken care of
        out(max(-ynow+2,1):min(yw,yw+ys-ynow-yw+1),max(-xnow+2,1):min(xw,xw+xs-xnow-xw+1))=out(max(-ynow+2,1):min(yw,yw+ys-ynow-yw+1),max(-xnow+2,1):min(xw,xw+xs-xnow-xw+1))+img(max(ynow,1):min(ynow+yw-1,ys),max(xnow,1):min(xnow+xw-1,xs));       
        xnow=xnow+xw;
    end
    xnow=xstart;
    ynow=ynow+yw;
end
